package cn.edu.ujs.coor.model;

import lombok.Data;

import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.io.Serializable;
import java.util.Date;

/**
 * Entity 公共字段抽离
 *
 * @author 柳曾雄
 * @date 2018-07-16
 */
@Data
@MappedSuperclass
public class BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 备注
     */
    protected String remark;

    /**
     * 创建时间
     */
    protected Date createTime;

    /**
     * 更新事件
     */
    protected Date updateTime;

    @PrePersist
    protected void perPersist () {
        Date now = new Date();
        setCreateTime(now);
        setUpdateTime(now);
    }

    @PreUpdate
    protected void perUpdate () {
        setUpdateTime(new Date());
    }
}
